﻿#include "nmpiece.h"

NMPiece::NMPiece()
{
    m_Quadrados << QRect(QPoint(s_QuadLength.width(), 0), s_QuadLength);
    m_Quadrados << QRect(QPoint(2 * s_QuadLength.width(), 0), s_QuadLength);
    m_Quadrados << QRect(QPoint(0, s_QuadLength.height()), s_QuadLength);
    m_Quadrados << QRect(QPoint(s_QuadLength.width(), s_QuadLength.height()),
                                s_QuadLength);
    m_Cor = QColor(174,174,0,220);
    m_Rot = false;
    m_TriedRot = false;
}

QList<QRect> NMPiece::rotacione(){
    QTransform tab;
    QList<QRectF> tempF;
    QList<QRect> ret;

    if(m_Rot) tab = tab.rotate(-90.0);
    else tab = tab.rotate(90.0);

    for(int i = 0;i < m_Quadrados.size();++i)
        tempF << QRectF(m_Quadrados[i]);

    for(int i = 1;i < tempF.size();++i){
        tempF[i].moveTo((tempF[i].x() - tempF[0].center().x()),
                      (tempF[i].y() - tempF[0].center().y()));
        if(m_Rot) tempF[i].setTopLeft(tempF[i].topRight()*tab);
        else tempF[i].setTopLeft(tempF[i].bottomLeft()*tab);
        tempF[i].setSize(QSizeF(s_QuadLength));
        tempF[i].moveTo((tempF[i].x() + tempF[0].center().x()),
                      (tempF[i].y() + tempF[0].center().y()));
    }

    for(int i = 0;i < tempF.size();++i)
        ret << tempF[i].toRect();

    m_TriedRot = true;
    return ret;
}

